Container: Don’t scroll to unset focus child coord
authorDaniel Boles <dboles@src.gnome.org>
Mon, 7 Aug 2017 17:32:57 +0000 (18:32 +0100)
committerDaniel Boles <dboles@src.gnome.org>
Mon, 7 Aug 2017 18:21:09 +0000 (19:21 +0100)
commit23b6699ec35d069c3f4a7b3a90bb5881740aab8e
treeb187601267e076f5c4f340be4b02eac25af47c2d
parentc4865bed432073ff8ed0551e16169c57f5633b32
Container: Don’t scroll to unset focus child coord

In gtk_container_real_set_focus_child(), we try to scroll to the
position of the new :focus-child if we have h or v adjustments.

gtk_widget_translate_coordinates() returns FALSE if neither widget is
realized or in other situations that cause output parameters x and y not
to be set. Thus, if the caller did not initialise x/y and uses them even
if the function returned FALSE, they are using uninitialised variables.

In gtk_container_real_set_focus_child(), we did not check the return
value but merrily went ahead and used x and y regardless. This is UB, as
revealed by Valgrind, as well as being pointless.

The trivial fix is to exit early if (!gtk_widget_translate_coordinates).

https://bugzilla.gnome.org/show_bug.cgi?id=776909
gtk/gtkcontainer.c